<template>
	<div>
		<!-- ↓↓↓↓ 学生的页面 -->
		<div v-if="userInfo.roles[0]==='STUDENT'">
            <limiteSignIn v-if="taskInfo.limited" :signInTaskInfo="taskInfo"></limiteSignIn>
            <aKeySignIn v-else :signInTaskInfo="taskInfo"></aKeySignIn>
        </div>
		<!-- ↓↓↓↓ 教师的页面 -->
        <div v-else>
            <startSignIn></startSignIn>
        </div>
	</div>

    
</template>

<script>
	import { viewTaskForStudent} from '@/api/signIn.js';
	import limiteSignIn from '../../components/signIn/limiteSignIn.vue';
    import aKeySignIn from '../../components/signIn/aKeySignIn.vue';
    import startSignIn from '../../components/signIn/startSignIn.vue';
	export default {
		components: {
			limiteSignIn,
            aKeySignIn,
            startSignIn
		},
        created() {
            this.userInfo = JSON.parse(localStorage.getItem('userInfo'));
			this.detailBankeInfo = JSON.parse(localStorage.getItem('detailBankeInfo'));
			if(this.userInfo.roles[0]==='STUDENT') {
				this.viewTaskForStudentALL(this.detailBankeInfo.id);
							
			}
        },
		data() {
			return {				
                role: '',
				userInfo: {},				
				taskTotal: 20,
				taskInfo: {},
			}
		},
		computed: {
			
		},
		methods: {
			async viewTaskForStudentALL(courseId) {
                let curPage = 1;                
                while(this.taskTotal > (curPage-1)*10) {
                    await viewTaskForStudent(curPage ,10 ,courseId).then(res => {
                        console.log(res);
                        if(res.data.code === 0) {
                            this.taskTotal = res.data.data.total;
                            for(let r of res.data.data.records) {                            
                                if(!r.ended) { // 如果课程没结束
                                    console.log('没结束的课程信息');
                                    console.log(r); // 没结束的课程信息
                                    this.taskInfo = r;
									localStorage.setItem('signInTaskInfo' , JSON.stringify(r));
                                    break;
                                }
                            }                     
                        } else {
                            this.taskTotal = 0;
                        }
                    }).catch(err => console.log(err));
                    curPage++;
                }                
            },			
		}
	}
</script>

<style>
    
</style>
